﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Action.Entity;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_RoleManager_EditorRole :PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Action.UserRole opRole = new PowerCreator.LMS.Web.Action.UserRole();
    PowerCreator.LMS.Web.Action.Action opAction = new PowerCreator.LMS.Web.Action.Action();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["RoleID"] != null)
                ViewState["RoleID"] = Request.QueryString["RoleID"].ToString();

            InitPage();
        }
    }

    /// <summary>
    /// 初始化界面信息，多语言项
    /// </summary>
    protected override void InitPage()
    {
    //    lbl_RoleName.Text = GetLanageValueByKey("lbl_EditorRole_RoleName", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    lbl_RoleDesc.Text = GetLanageValueByKey("lbl_EditorRole_RoleDesc", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    lbl_InfoTitle.Text = GetLanageValueByKey("lbl_EditorRole_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Update.Text = GetLanageValueByKey("btn_EditorRole_Update", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Back.Text = GetLanageValueByKey("btn_EditorRole_Back", PowerCreator.LMS.Language.LanagetItemType.Page);

        VOTRole vo = opAction.LoadRole(int.Parse(ViewState["RoleID"].ToString()));

        txt_RoleDesc.Text = vo.RoleDescription;
        txt_RoleName.Text = vo.RoleName;
    }

    private bool CheckPageData()
    {
        if (string.IsNullOrEmpty(txt_RoleName.Text))
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_msg_RoleName_minlength", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        if (txt_RoleName.Text.Length > 20)
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_msg_RoleName_maxlength", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        if (txt_RoleDesc.Text.Length > 200)
        {
            lbl_msg_RoleDesc.Text = GetLanageValueByKey("lbl_msg_RoleDesc_maxlength", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }

        return true;
    }

    protected void btn_AddAdminGroup_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        VOTRole vo = opAction.LoadRole(int.Parse(ViewState["RoleID"].ToString()));
        vo.RoleDescription = txt_RoleDesc.Text;
        vo.RoleName = txt_RoleName.Text;

        if (opAction.UpdateRole(vo))
        {
            string url = "ManagerRole.aspx";
            Script.RedirectURL(url);
        }
        else
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_msg_update_nosoureccd", PowerCreator.LMS.Language.LanagetItemType.MSG);
        }
    }
    protected void btn_Back_Click(object sender, EventArgs e)
    {
        string url = "ManagerRole.aspx";
        Script.RedirectURL(url);
    }
}
